package problems;

import interfaces.EulerProblemInterface;

import java.util.List;

import utility.PrimeGenerator;
import utility.ProblemSpecifics;

public class EulerProblem010 implements EulerProblemInterface {

	private static final int UPPER_BOUNDARY = 2000000;
	// TODO try and solve member and public method implementation redundancy
	// with object composition rather than inheritance
	private ProblemSpecifics problemSpecifics;

	public EulerProblem010() {
		String problemStatement = "Find the sum of all the primes below two million.";
		problemSpecifics = new ProblemSpecifics(problemStatement);
	}

	public void solve() {
		PrimeGenerator primeGen = new PrimeGenerator();
		primeGen.generateUpTo(UPPER_BOUNDARY);
		List<Long> listOfPrimes = primeGen.reportPrimes();
		long sumOfPrimes = sum(listOfPrimes);
		problemSpecifics.setResultAndMarkSolved(sumOfPrimes);
	}

	private long sum(List<Long> listOfPrimes) {
		long sum = 0;
		for (Long prime : listOfPrimes) {
			sum += prime;
		}
		return sum;
	}

	public long reportResult() {
		return problemSpecifics.reportResult();
	}

	public ProblemStatus reportStatus() {
		return new ProblemStatus(problemSpecifics.isSolved());
	}

	public String stateTheProblem() {
		return problemSpecifics.stateTheProblem();
	}
}
